import { defineStore } from "pinia";
import { showToast } from "vant";
interface CarList {
    carList: any[]
}
export const carListStore = defineStore('carList', {
    state: (): CarList => {

        return {
            carList: []
        }
    }, getters: {

    },
    actions: {
        delCarr(item: any) {
            this.carList = [...item]
            showToast('删除商品成功')

        },
        addCar(item: any) {
            if (this.carList.length == 0) {
                this.carList.unshift(item)
                showToast('商品添加成功')
            } else {
                for (var i in this.carList) {
                    if (this.carList[i].id == item.id) {
                        this.carList[i].count++
                        showToast('该商品已购物车中，商品数量+1')
                        return
                    } else {
                        this.carList.unshift(item)
                        showToast('商品添加成功')
                        return

                    }
                }
            }

        }

    }
})

interface order {
    order: any[]
}
export const orderStore = defineStore('order', {
    state: (): order => {

        return {
            order: []
        }
    }, getters: {

    },
    actions: {
        submitOrder(item: Array<object>) {
            this.order = item

        }
    }
})

interface historyOrder {
    historyOrder: any[]
}
export const historyOrderStore = defineStore('historyOrder', {
    state: (): historyOrder => {

        return {
            historyOrder: []
        }
    }, getters: {

    },
    actions: {
        submitOrder(item: Array<object>) {
            this.historyOrder.push(item)
        }
    }
})